package com.tuanzi.loan.web.bean.family;

import com.tuanzi.loan.business.service.family.UpdateVersionService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.vo.request.family.UpdateVersionSearchRequest;
import com.tuanzi.loan.vo.response.family.UpdateVersionSearchResponse;
import com.tuanzi.loan.web.configuration.JSFListingSessionBean;
import com.tuanzi.loan.web.lazy.family.UpdateVersionLazyDataModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.faces.bean.ViewScoped;

@Data
@Debug
@Component
@ViewScoped
@EqualsAndHashCode(callSuper = true)
public class UpdateVersionListBean extends JSFListingSessionBean<UpdateVersionSearchRequest, UpdateVersionSearchResponse> {

	@Autowired
	private UpdateVersionService updateVersionService;

	@Override
	protected String page() {
		return "/views/family/update-version/list.xhtml";
	}

	@Override
	protected void initLazyDataModel() {
		$ = new UpdateVersionSearchRequest();
		lazyDataModel = new UpdateVersionLazyDataModel($, session, updateVersionService);
	}

	public String onAdd() {
		return redirect("/views/family/update-version/info.xhtml");
	}

	public String onEdit(Integer id) {
		return redirect("/views/family/update-version/info.xhtml?id=" + id);
	}

	public void onOnline(Integer id){
		if (id == null) {
			addErrorMessage("系统错误，请联系管理员");
		}
		updateVersionService.online(id);
		addSuccessfullyMessage();
	}

	public void onReset() {
		initLazyDataModel();
	}
}
